-- open_grid
-- create by cheny3
-- 开格子

return {
    -- 判断
    canTrigger = function(args)
        -- 判断是否有可以开的格子
        local ableToOpen = AutoFightM.getData()["ableToOpen"];
        if ableToOpen and #ableToOpen > 0 then
            return true;
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        -- 有显示的怪物，翻格子概率执行
        local chanceRange = args["monster_chance"];
        if chanceRange and #aliveMonsters > 0 then
            if math.random(chanceRange[2]) > chanceRange[1] then
                -- 概率没触发
                return false;
            end
        end

        local ableToOpen = AutoFightM.getData()["ableToOpen"];
        if not ableToOpen or #ableToOpen <= 0 then
            return false;
        end

        -- 随机开一个格子
        local index = math.random(#ableToOpen);
        DungeonActionM.go("open_grid", ableToOpen[index]);

        -- 抛出事件
        EventMgr.fire(event.PLAYER_MOVE, ableToOpen[index]);
        return true;
    end,
};
